﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;
using WCF_PRACTICELib;

namespace WCF_PRACTICEHost
{
    public partial class MathWinService : ServiceBase
    {
        private ServiceHost myHost;
        public MathWinService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            if (myHost != null)
            {
                myHost.Close();
                myHost = null;
            }

            // Create the host and specify a URL for an HTTP binding.
            myHost = new ServiceHost(typeof(MathService),
                new Uri("http://localhost:8080/MathServiceLibrary"));
            myHost.AddDefaultEndpoints();

            //// Create the host and specify a URL for an HTTP binding.
            //myHost = new ServiceHost(typeof(MathService));
            //Uri address=new Uri("http://localhost:8080/MathServiceLibrary");
            //WSHttpBinding binding=new WSHttpBinding();
            //Type contract = typeof (IBasicMath);
            //myHost.AddServiceEndpoint(contract, binding, address);

            // Open the host.
            myHost.Open();
        }

        protected override void OnStop()
        {
            // Shut down the host.
            if (myHost != null)
                myHost.Close();
        }
    }
}
